package com.dongqi.detectionResult.controller;

import com.dongqi.detectionResult.dto.DetectionResultDTO;
import com.dongqi.detectionResult.service.DetectionResultService;
import com.dongqi.utils.RestResult;
import com.dongqi.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 检测结果控制层
 */
@Slf4j
@RestController
@RequestMapping(value = "/detectionResult")
public class DetectionResultController {
    @Autowired
    private DetectionResultService detectionResultService;

    /**
     * 检测结果查询接口
     *
     * @param map
     * @return
     */
    @PostMapping("/getResultByTaskNo")
    public RestResult getResultByTaskNo(@RequestBody Map<String, String> map) {
        //if (null == map.get("detectTaskNo") || StringUtils.isEmpty(map.get("detectTaskNo"))) {
        //    return RestResult.error("传入参数有误");
        //}
        List<DetectionResultDTO> detectionResultDTOList = detectionResultService.getResultByTaskNo(map);
        return RestResult.success(detectionResultDTOList);
    }


    /**
     * 查询检测报告
     *
     * @param map
     * @return
     */
    @PostMapping("/getDetailByDeviceNo")
    public RestResult getDetailByDeviceNo(@RequestBody Map<String, String> map) {
        if (null == map.get("deviceNo") || StringUtils.isEmpty(map.get("deviceNo"))) {
            return RestResult.error("传入参数有误");
        }
        // TODO: 2023/12/26  
        DetectionResultDTO detectionResultDTOList = detectionResultService.getDetailByDeviceNo(map.get("deviceNo"));

        return RestResult.success(detectionResultDTOList);
    }
}
